package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.Product;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.service.ProductService;
import com.spzx.product.service.ProductSpecService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品接口管理")
@RestController
@RequestMapping("/product")
public class ProductController extends BaseController {

    @Autowired
    private ProductService productService;
    //查询商品列表
    @Operation(summary = "查询商品列表")
    @GetMapping("/list")
    public TableDataInfo list(Product product){
        startPage();
        List<Product> list = productService.selectProductList(product);
        return getDataTable(list);//查询成功或者失败
    }

    @Operation(summary = "添加商品")
    @GetMapping("/add")
    public AjaxResult add(@RequestBody Product product){
        return toAjax(productService.insertProuduct(product));
    }

    //获取商品详细信息
    @Operation(summary = "获取商品详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return success(productService.selectProductById(id));
    }

    //修改商品
    @Operation(summary = "修改商品")
    @PutMapping
    public AjaxResult edit(@RequestBody Product product){
        return toAjax(productService.updateProduct(product));
    }

    //删除
    @Operation(summary = "删除商品")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long[] ids){
       return toAjax( productService.deleteProductByIds(ids));
    }
}
